import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.util.List;
import java.util.StringTokenizer;

/**
 * 功能: 描述.
 *
 * @author Fire Fish
 * @since 2022-07-31 6:55 PM
 */
public class ConvertGBK2UTF8 {

    public static void main(String[] args) {

        /**
         * 源：gbk
         * 目标：utf-8
         */

        File file = new File("src/main/java");
        List<File> files = FileUtil.loopFiles(file, t -> {
            return t.getName().endsWith(".java");
        });

        files.forEach(t -> {
            try {
                File dest = new File(t.toString().replace("src", "ddd"));
                FileUtil.mkParentDirs(dest);
                InputStreamReader in = new InputStreamReader(new FileInputStream(t), "GBK");
                OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(dest), "UTF-8");
                IoUtil.copy(in,out);
            } catch ( Exception e) {
                throw new RuntimeException(e);
            }
        });

        System.out.println(files.size());
//        FileUtil.walkFiles(file,t -> {
//            System.out.println(t.getAbsolutePath());
//        });

    }
}
